#! /usr/bin/perl -w

# CGI-Ajax: example script 'pjx_fname.pl'
#
# INSTALL: place in an apache location that can execute perl scripts
#
# this is an example script of how you would use fname to define
# your own CGI param name for passing exported function names
#
# 2008 Michael Kyraha, http://michael.kyraha.com/

use strict;
use CGI;      # or any other CGI:: form handler/decoder
use CGI::Ajax;

my $cgi = new CGI;
my $pjx = new CGI::Ajax( 'exported_func' => \&perl_func );

$pjx->fname('myfunc'); # Should be called before any output

print $pjx->build_html( $cgi, \&Show_HTML);

sub perl_func {
  my $input = shift;
  my $output .= sprintf "CGI params: %s", join ", ", map sprintf("%s=%s",$_,$cgi->param($_)), $cgi->param;
  return( $output );
}

sub Show_HTML {
  my $html = <<EOHTML;
  <HTML>
  <BODY>
    Enter something: 
      <input type="text" name="val1" id="val1"
       onkeyup="exported_func( ['val1'], ['resultdiv'] );">
    <br>
    <div id="resultdiv"></div>
  </BODY>
  </HTML>
EOHTML
  return $html;
}
